<?php
namespace Api\Controller;
use App\Controller\LoginController;//登录类  
    class ApiController {

        /**
         * 登录
         */
        public function login(){
            //post,get均可
            $password = I('password');//密码
            $username = I('username');//用户名
            $username = empty($username) ? '' : $username;
            $password = empty($password) ? '' : $password;
            $loginObj = new LoginController();
            $ret = $loginObj->login($username, $password);
            if ($ret['code'] == 0) {
                $return = array(
                    'code' => '0',
                    'status' => 'success',
                    'msg' => '成功'
                );
            } elseif ($ret['code'] == 1) {
                $return = array(
                    'code' => '1',
                    'status' => 'fail',
                    'msg' => '账号或密码错误'
                );
            } else {
                $return = array(
                    'code' => '-1',
                    'status' => 'fail',
                    'msg' => '未知错误'
                );
            }
            echo json_encode($return); 
        }
    }  